﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using MySchool;

namespace MyKTV
{
    public partial class xinzeng_geshou : Form
    {
        DBHelper db = new DBHelper();
        DataSet set = new DataSet();
        SqlCommand comm;
        string name;
        string leixing;
        string sql;
        int i;
        public xinzeng_geshou()
        {
            InitializeComponent();
        }

        private void xinzeng_geshou_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string sql = "select * from singer_type";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, db.Connection);
            adapter.Fill(set, "singer_type");
            this.comboBox1.DataSource = set.Tables["singer_type"];
            this.comboBox1.ValueMember = "singertype_id";
            this.comboBox1.DisplayMember = "singertype_name";
            db.CloseConnection();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Trim().Equals(string.Empty)|| this.comboBox1.Text.Equals(string.Empty))
            {
                MessageBox.Show("歌手信息不全");
                return;
            }



            db.OpenConnection();
            string sql = "select * from singer_info where singer_name=N'" + this.textBox1.Text+"'";
            SqlCommand comm = new SqlCommand(sql,db.Connection);
            int i = Convert.ToInt32(comm.ExecuteScalar());
            if (i>0)
            {
                MessageBox.Show("歌手名重复","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                return;
            }
            else
            {
                string h = this.comboBox1.Text;
                if (this.comboBox1.Text == "大陆")
                {
                    leixing = "1";
                }
                else if (this.comboBox1.Text == "香港")
                {
                    leixing = "2";
                }
                else if (this.comboBox1.Text == "台湾")
                {
                    leixing = "3";
                }
                else if (this.comboBox1.Text == "欧美")
                {
                    leixing = "4";
                }
                else if (this.comboBox1.Text == "日韩")
                {
                    leixing = "5";
                }
                else
                {
                    leixing = "0";
                    MessageBox.Show("有误");
                    return;
                }

                if (this.radioButton1.Checked == true)
                {
                    sql = "insert singer_info(singer_name,singertype_id,singer_gender,singer_photo_url,singer_description)values(N'" + this.textBox1.Text + "','" + leixing + "',N'" + this.radioButton1.Text + "',N'" + name + "',N'"+this.textBox2.Text+"')";
                    
                }
                else if (this.radioButton2.Checked == true)
                {
                    sql = "insert singer_info(singer_name,singertype_id,singer_gender,singer_photo_url,singer_description)values(N'" + this.textBox1.Text + "','" + leixing + "',N'" + this.radioButton2.Text + "',N'" + name + "',N'" + this.textBox2.Text + "')";
                }
                else if (this.radioButton3.Checked == true)
                {
                    sql = "insert singer_info(singer_name,singertype_id,singer_gender,singer_photo_url,singer_description)values(N'" + this.textBox1.Text + "','" + leixing + "',N'" + this.radioButton3.Text + "',N'" + name + "',N'" + this.textBox2.Text + "')";
                }
                comm = new SqlCommand(sql, db.Connection);
                i = comm.ExecuteNonQuery();
                if (i > 0)
                {
                    MessageBox.Show("成功");
                }
            }

            




        }

       

        private void button1_Click(object sender, EventArgs e)
        {
            


            //弹出选择文件框
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //打开文件框
            DialogResult result = openFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                // Image.FromFile从路径中拿到图片
                this.pictureBox1.Image = Image.FromFile(openFileDialog.FileName);
                name = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
            }
            //名字获取
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
